package com.woniuxy.kaer.tenants.controller;


import cn.hutool.core.bean.BeanUtil;
import com.woniuxy.kaer.commons.jwtUtil.JwtUtil;
import com.woniuxy.kaer.commons.util.Result;
import com.woniuxy.kaer.tenants.dto.SettleApplyDto;
import com.woniuxy.kaer.tenants.from.TenantsApplyAuditFrom;
import com.woniuxy.kaer.tenants.from.TenantsApplyFrom;
import com.woniuxy.kaer.tenants.param.TenantsApplyAuditParam;
import com.woniuxy.kaer.tenants.param.TenantsApplyParam;
import com.woniuxy.kaer.tenants.service.SettledService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 程诗洋
 * @since 2025年02月17日
 */
//商家入驻申请
@RestController
@RequestMapping("/settled")
@Api(tags = "商家入驻申请接口")
public class SettledController {

    @Resource
    private SettledService settledService;
    @Resource
    private JwtUtil jwtUtil;

    //商家入驻申请
    @ApiOperation("商铺入驻申请")
    @PostMapping("/settledApply")
    public Result settledApply(TenantsApplyFrom from,@RequestHeader("token") String token)throws Exception{
        TenantsApplyParam tenantsApplyParam = BeanUtil.toBean(from, TenantsApplyParam.class);
        Integer founderId = jwtUtil.getFounderId(token);
        tenantsApplyParam.setFounderId(founderId);
        settledService.settledApply(tenantsApplyParam);
        return Result.succeed("入驻申请提交成功",null);
    }
    //商家入驻申请审核
    @ApiOperation("商家入驻申请审核")
    @PostMapping("/settledApplyReview")
    public Result settledApplyAudit(@RequestBody TenantsApplyAuditFrom from)throws Exception{
        TenantsApplyAuditParam tenantsApplyAuditParam = BeanUtil.toBean(from, TenantsApplyAuditParam.class);
        settledService.settledApplyAudit(tenantsApplyAuditParam);
        return Result.succeed("入驻申请审核成功",null);
    }
    //拒绝商家入驻申请
    @ApiOperation("拒绝商家入驻申请")
    @PostMapping("/refuseSettledApply")
    public Result refuseSettledApply(@RequestBody TenantsApplyAuditFrom from)throws Exception{
        TenantsApplyAuditParam tenantsApplyAuditParam = BeanUtil.toBean(from, TenantsApplyAuditParam.class);
        settledService.refuseSettledApply(tenantsApplyAuditParam);
        return Result.succeed("入驻申请审核成功",null);
    }

    //查询入驻申请
    @ApiOperation("查询入驻申请")
    @GetMapping("/getSettledApply")
    public Result getSettledApply(@RequestHeader("token") String token)throws Exception{
        Integer founderId = jwtUtil.getFounderId(token);
        List<SettleApplyDto> settleApplyDtos =settledService.getSettledApply(founderId);
        return Result.succeed("查询申请成功",settleApplyDtos);
    }
    @ApiOperation("平台查询入驻申请")
    @GetMapping("/getSettledApplyByManager")
    public Result getSettledApplyByManager()throws Exception{
        List<SettleApplyDto> settleApplyDtos =settledService.getSettledApplyByManager();
        return Result.succeed("查询申请成功",settleApplyDtos);
    }

}

